import 'package:flutter/material.dart';
import '../bean/beans.dart';
import 'package:bear_story/views.dart';
import '../page/book.dart';

class MorePage extends StatefulWidget {
  final List<Book> books;
  final String title;

  MorePage(this.title, this.books);

  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return _MorePageState(title, books);
  }
}

class _MorePageState extends State<MorePage> {
  List<Book> books = [];
  final String title;

  _MorePageState(this.title, this.books);

  Future refresh() async {}

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      appBar: AppBar(
        backgroundColor: main_theme_color,
        title: Text(title == null ? "" : title),
        centerTitle: true,
        elevation: 0,
      ),
      body: RefreshIndicator(
          color: main_theme_color,
          child: Container(
            color: background_color,
            child: Container(
              color: Colors.white,
              padding: EdgeInsets.only(left: main_padding_left, right: main_padding_left),
              child: GridView.builder(
                padding: EdgeInsets.only(top: 14, bottom: 0),
                itemCount: books.length,
                gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                  crossAxisCount: 2,
                  mainAxisSpacing: main_padding_top,
                  crossAxisSpacing: main_padding_left,
                  childAspectRatio: getAlbumChildAspectRatio(MediaQuery.of(context).devicePixelRatio, 2),
                ),
                itemBuilder: (BuildContext context, int index) {
                  return GestureDetector(
                    onTap: () {
                      pushPage(context, BookPage(books[index]));
                    },
                    child: BookAlbumView(books[index]),
                  );
                },
              ),
            ),
          ),
          onRefresh: refresh),
    );
  }
}
